#!/usr/bin/python3

import sys
import asyncio
import qemu.qmp

c = None

async def main():
    global c

    c = qemu.qmp.QMPClient()

    await c.connect("/home/fpemud/workspace/wstage4/scripts/t/vm-ctrl.socket")
    # await c.connect("/home/fpemud/maint/librungame-repacks-maintenance-scripts/__temp__/work/vm-ctrl.socket")

    # print(c.await_greeting)
    # print(c.greeting)

    res = await c.execute('query-status')
    print(f"VM status: {res['status']}")

    # res = await c.execute('query-mice')
    # print(f"VM status: {res}")

    # while True:
    #     import time
    #     time.sleep(1)

    #     x = 32500
    #     y = 32000

    #     await c.execute("input-send-event", {
    #         "events": [
    #             { "type": "abs", "data" : { "axis": "x", "value" : x } },
    #             { "type": "abs", "data" : { "axis": "y", "value" : y } },
    #         ]
    #     })

    #     time.sleep(1)

        # btn = "right"
        # if btn is not None:
        #     await c.execute("input-send-event", {
        #         "events": [
        #             { "type": "btn", "data" : { "down": True, "button": btn }},
        #         ],
        #     })
        #     await c.execute("input-send-event", {
        #         "events": [
        #             { "type": "btn", "data" : { "down": False, "button": btn }},
        #         ],
        #     })



    #await c.execute("send-key", {"keys": [{"type": "qcode", "data": "alt"},
    #                                      {"type": "qcode", "data": "f4"}]})
    await c.execute("screendump", {"filename": "a.ppm"})

    await c.disconnect()


asyncio.run(main())
